import axios from "axios";

export default function request(config) {
  const instance = axios.create({
    baseURL: 'https://api.shop.eduwork.cn', //这个是请求的域名
    // timeout: 10000,
  });

  //请求拦截 设置某些请求需要认证
  instance.interceptors.request.use(config => {
    // 这里请求带token
    if (window.localStorage.getItem('token')) {
      config.headers.Authorization = 'Bearer ' + window.localStorage.getItem('token');
    }
    return config;
  });

  // 响应的处理
  instance.interceptors.response.use(res => {
    return res;
  }, err => {
    if (err.response.status === 401) {
      Toast.fail('请先登录')
      router.push({ path: '/login' })
    }
    // Notify(err.response.data.errors[Object.keys(err.response.data.errors)[0]][0])
  });

  return instance(config);
}